home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / develop™ Technical Journal / develop Issue 24 code / Scriptable Database 1.0a11.sea / Scriptable Database 1.0a11 / Foundation / MarkToken.h / MarkToken.h
Encoding:
C/C++ Source or Header  |  1995-10-18  |  4.7 KB  |  146 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        MarkToken.h
  3.  
  4.     Contains:    A token that contains a set of other tokens
  5.  
  6.     Written by:    Andy Nicholas, Greg Anderson, Tom Conrad, Chris Bingham, Georgiann Puckett, John Thompson-Rohrlich
  7.  
  8.     Copyright:    © 1994-1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.          <5>      6/6/95    ga        
  11.  
  12. */
  13.  
  14. #ifndef MarkToken_h
  15. #define MarkToken_h
  16.  
  17. //
  18. // ProxyToken.h is needed because
  19. // TProxyToken is the base class of TMarkToken
  20. //
  21. #include "ProxyToken.h"
  22.  
  23. //
  24. // TAbstractIterator is the base class of TMarkIterator
  25. //
  26. #include "AbstractIterator.h"
  27.  
  28. class TScriptableObjectList;
  29.  
  30. #define cMarkToken 'mark'
  31.  
  32. //
  33. // Needed for a callback in MoreAEM
  34. //
  35. TAbstractScriptableObject* MarkTokenMergeProc(TAbstractScriptableObject* baseToken, TAbstractScriptableObject* mergeToken);
  36.  
  37. //========================================================================================
  38. //
  39. //    CLASS TMarkToken
  40. //
  41. //========================================================================================
  42.  
  43. class TMarkToken : public TProxyToken
  44.     {
  45. public:
  46.     DeclareSmallClassData(TMarkToken, TProxyToken);
  47.  
  48.                                         TMarkToken(TypeOfMarkToken markType) : fMarkList(nil), fIsUnionMark(markType) {};
  49.                                         TMarkToken(TScriptableObjectList* list, TypeOfMarkToken markType) : fMarkList(list), fIsUnionMark(markType) {};
  50.     virtual                                ~TMarkToken();
  51.  
  52.     virtual void                        CloneOwnedObjects();
  53.     
  54.     void                                IMarkToken();
  55.     void                                SetUnionMark(TypeOfMarkToken isUnionMark) { fIsUnionMark = isUnionMark; }
  56.     Boolean                                IsUnionMark() { return fIsUnionMark == kSingleItemOrUnion; }
  57.     
  58.     Boolean                                DerivedFromOSLClass(TTransaction* t, DescType objectClass);
  59.  
  60.     virtual TAbstractObjectIterator*    DirectObjectIterator(TTransaction*);
  61.     virtual TAbstractObjectIterator*    ElementIterator(TTransaction*);
  62.  
  63.     virtual TAbstractScriptableObject*    AdoptToken(TAbstractScriptableObject* token, TypeOfMarkToken);
  64.     virtual void                        AddThisToMarkToken(TAbstractScriptableObject*& markToken, TypeOfMarkToken);
  65.  
  66.     virtual void                        AdjustMarks(long newStart, long newStop);
  67.     
  68. protected:
  69.     
  70.     //
  71.     // fMarkList is a list of all of the tokens designated by the mark token
  72.     //
  73.     TScriptableObjectList*                fMarkList;
  74.     
  75.     //
  76.     // fIsUnionMark is true if this mark token was created in order to
  77.     // silently union together multiple hits to a request that is usually
  78.     // matched by a single token (e.g. AccessByName, as in 'folder "Bad Idea"
  79.     // of desktop', when there are two folders named "Bad Idea" on the desktop).
  80.     //
  81.     // Tokens unioned together in this manner will behave as a single
  82.     // container; for example, 'count folder "Bad Idea" of desktop each item' will
  83.     // return the sum of the number of items inside each folder named
  84.     // "Bad idea" on the desktop.  This is different than the behavior of
  85.     // non-union mark tokens; for example, 'count every folder of desktop
  86.     // whose name is "Bad Idea" each item' will return the number of
  87.     // folders named "Bad Idea" on the desktop, because 'whose' clauses do
  88.     // not generate union mark tokens.
  89.     //
  90.     // The only variation on behavior is in CaclulateCount and AccessByIndex.
  91.     // I was tempted to make a class TUnionMarkToken : public TMarkToken, but
  92.     // I was unsure if I might need to dynamicly transmogrify a non-union mark
  93.     // into a union mark.
  94.     //
  95.     TypeOfMarkToken                     fIsUnionMark;
  96.     };
  97.  
  98.  
  99. class TScriptableObjectListIterator;
  100.  
  101.  
  102. //========================================================================================
  103. // Class TMarkTokenIterator
  104. //========================================================================================
  105. class TMarkTokenIterator : public TAbstractObjectIterator
  106. {
  107. private:
  108.     TScriptableObjectListIterator*    fListIter;
  109.     TAbstractObjectIterator*        fCurrentIter;
  110.     Boolean                            fDirection;
  111.     
  112.     TScriptableObjectList*            fMarkList;
  113.     Boolean                            fIterateElements;
  114.     Boolean                            fRequireExists;
  115.     Boolean                            fDeleteListOnDestruction;
  116.     
  117. public:
  118.     TMarkTokenIterator(TScriptableObjectList* markList, Boolean iterateElements, Boolean requireExists, Boolean deleteListOnDestruction = false) :
  119.         fListIter(nil),
  120.         fCurrentIter(nil),
  121.         fDirection(kForwardIteration),
  122.         fMarkList(markList),
  123.         fIterateElements(iterateElements),
  124.         fRequireExists(requireExists),
  125.         fDeleteListOnDestruction(deleteListOnDestruction) { this->Reset(kForwardIteration); }
  126.  
  127.     virtual ~TMarkTokenIterator();
  128.     
  129.     //
  130.     // Interface to code to:
  131.     //
  132.     virtual void                        Reset(TTransaction* t, Boolean iterationDirection = kForwardIteration);
  133.     virtual Boolean                        More(TTransaction*) const;
  134.     virtual void                        Next(TTransaction*);
  135.     virtual TAbstractScriptableObject*    Current(TTransaction*);
  136.  
  137.     virtual void                        SearchDeep(TTransaction* t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec);
  138.     
  139. private:
  140.     void                                SetupCurrentIterator(TTransaction* t);
  141. };
  142.  
  143.  
  144. #endif
  145.  
  146.